﻿using System;
using System.Collections;
using UnityEngine;

namespace RootMotion.Demos
{
	// Token: 0x020000C2 RID: 194
	public class PlatformRotator : MonoBehaviour
	{
		// Token: 0x060005E6 RID: 1510 RVA: 0x00037908 File Offset: 0x00035B08
		public void Start()
		{
			this.defaultRotation = base.transform.rotation;
			this.targetPosition = base.transform.position + this.movePosition;
			this.r = base.GetComponent<Rigidbody>();
			base.StartCoroutine(this.SwitchRotation());
		}

		// Token: 0x060005E7 RID: 1511 RVA: 0x0003795C File Offset: 0x00035B5C
		public void FixedUpdate()
		{
			this.r.MovePosition(Vector3.SmoothDamp(this.r.position, this.targetPosition, ref this.velocity, 1f, this.moveSpeed));
			if (Vector3.Distance(base.GetComponent<Rigidbody>().position, this.targetPosition) < 0.1f)
			{
				this.movePosition = -this.movePosition;
				this.targetPosition += this.movePosition;
			}
			this.r.MoveRotation(Quaternion.RotateTowards(this.r.rotation, this.targetRotation, this.rotationSpeed * Time.deltaTime));
		}

		// Token: 0x060005E8 RID: 1512 RVA: 0x00037A10 File Offset: 0x00035C10
		public IEnumerator SwitchRotation()
		{
			for (;;)
			{
				float angle = UnityEngine.Random.Range(-this.maxAngle, this.maxAngle);
				Vector3 axis = UnityEngine.Random.onUnitSphere;
				this.targetRotation = Quaternion.AngleAxis(angle, axis) * this.defaultRotation;
				yield return new WaitForSeconds(this.switchRotationTime + UnityEngine.Random.value * this.random);
			}
			yield break;
		}

		// Token: 0x060005E9 RID: 1513 RVA: 0x00037A2C File Offset: 0x00035C2C
		public void OnCollisionEnter(Collision collision)
		{
			if (collision.gameObject.layer == this.characterLayer)
			{
				CharacterThirdPerson component = collision.gameObject.GetComponent<CharacterThirdPerson>();
				if (component == null)
				{
					return;
				}
				if (component.smoothPhysics)
				{
					component.smoothPhysics = false;
				}
			}
		}

		// Token: 0x060005EA RID: 1514 RVA: 0x00037A7C File Offset: 0x00035C7C
		public void OnCollisionExit(Collision collision)
		{
			if (collision.gameObject.layer == this.characterLayer)
			{
				CharacterThirdPerson component = collision.gameObject.GetComponent<CharacterThirdPerson>();
				if (component == null)
				{
					return;
				}
				component.smoothPhysics = true;
			}
		}

		// Token: 0x040004F5 RID: 1269
		public float maxAngle = 70f;

		// Token: 0x040004F6 RID: 1270
		public float switchRotationTime = 0.5f;

		// Token: 0x040004F7 RID: 1271
		public float random = 0.5f;

		// Token: 0x040004F8 RID: 1272
		public float rotationSpeed = 50f;

		// Token: 0x040004F9 RID: 1273
		public Vector3 movePosition;

		// Token: 0x040004FA RID: 1274
		public float moveSpeed = 5f;

		// Token: 0x040004FB RID: 1275
		public int characterLayer;

		// Token: 0x040004FC RID: 1276
		public Quaternion defaultRotation;

		// Token: 0x040004FD RID: 1277
		public Quaternion targetRotation;

		// Token: 0x040004FE RID: 1278
		public Vector3 targetPosition;

		// Token: 0x040004FF RID: 1279
		public Vector3 velocity;

		// Token: 0x04000500 RID: 1280
		public Rigidbody r;
	}
}
